package com.lwt.db137.controller;

import com.lwt.db137.bean.Menu;
import com.lwt.db137.bean.Role;
import com.lwt.db137.commen.R;
import com.lwt.db137.service.RoleService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lwt
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:42
 */
@CrossOrigin(origins = "*")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;
    // 查询所有角色
    @GetMapping("roles")
    public R getAllRoles() {
        return new R().addData("roles", roleService.list());
    }
    //根据id查询角色
    @GetMapping("selectRoleById/{userid}")
    public R getRoleById(@PathVariable("userid") int  userid) {
        return new R().addData("roleById", roleService.selectRoleById(userid));
    }
    //添加
    @PostMapping("addRole")
    public int addMenu(@RequestBody Role role){
        return roleService.insert(role);
    }

    //修改
    @PostMapping("updateRole")
    public int updateMenu(@RequestBody Role role){
        return roleService.updateMenuById(role);
    }
    //删除
    @PostMapping("deleteRole")
    public int deleteMenu(@RequestParam("id") Integer id){
        return roleService.deleteById(id);
    }
}
